package com.zzptc.easyshop.factory;

import com.zzptc.easyshop.dao.IDAO;
import com.zzptc.easyshop.db.Myutil;

import java.util.Map;

public class DaoFactoryImp implements IFactory {
    //饿汉式
    private static DaoFactoryImp daoFactoryImp=new DaoFactoryImp();
    private DaoFactoryImp(){}
    public static DaoFactoryImp getlnstance(){
        return daoFactoryImp;
    }
    //根据参数创建DAO的方法
    @Override
    public IDAO createDAO(String type) throws Exception {
        Map<String,String> map=Myutil.readXML();
        String daostring=map.get(type);
        IDAO dao=(IDAO)Class.forName(daostring).newInstance();
        return dao;
    }
    //测试
    public static void main(String[] args) {
        try {
            DaoFactoryImp.getlnstance().createDAO("userdao");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
